package com.probiz.estore.system.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.Constants;
import com.probiz.estore.system.dao.SelfCollectionCentreDao;
import com.probiz.estore.common.model.system.SelfCollectionCentre;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;
import com.probiz.estore.core.model.BaseObject;

/**
 * Dao implementation for SelfCollectionCentre.
*/
public class SelfCollectionCentreDaoImpl extends HibernateGenericDaoImpl<SelfCollectionCentre> implements SelfCollectionCentreDao {

	@Override
	protected void initFilterHqlMap() {
		filterHqlMap.put(BaseObject.FilterHqlName.DEFAULT, "select s from SelfCollectionCentre s");
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.system.dao.SelfCollectionCentreDao#findActiveSelfCollectionCentres()
	 */
	public List<SelfCollectionCentre> findActiveSelfCollectionCentres() {
		String propertyName = "status";
		return this.listByProperty(propertyName, Constants.STATUS_ACTIVE);
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.system.dao.SelfCollectionCentreDao#isExistedSelfCollectionCentreForUpdate(com.probiz.estore.common.model.system.SelfCollectionCentre)
	 */
	public boolean isExistedSelfCollectionCentreForUpdate(SelfCollectionCentre selfCollectionCentre) {
		String sql = "select s from SelfCollectionCentre s where s.selfCollectionCentreId!=? and  s.selfCollectionCentreName=?";
		List<SelfCollectionCentre> list = this.findByHql(sql, selfCollectionCentre.getSelfCollectionCentreId(), selfCollectionCentre.getSelfCollectionCentreName());
		if (list != null && list.size() > 0) {
			return true;
		} else {
			return false;
		}
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.system.dao.SelfCollectionCentreDao#getSelfCollectionCentreListByRegionId(java.lang.Integer)
	 */
	public List<SelfCollectionCentre> getSelfCollectionCentreListByRegionId(Integer regionId){
		StringBuilder hqlsb = new StringBuilder();
		hqlsb.append("select s from SelfCollectionCentre s where s.status=").append(Constants.STATUS_ACTIVE);
		hqlsb.append(" and s.regionId = ").append(regionId);
		return this.findByHql(hqlsb.toString());
	}
	
	

}
